package com.hymjweb.demo.hymj.finance_manage.invoice_register.detail.mapper;

import com.hymjweb.demo.hymj.finance_manage.invoice_register.detail.bean.CwInvoiceRegisterDetailPojo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Component;

@Mapper
@Component
public interface CwInvoiceRegisterDetailMapper {



    class CwInvoiceRegisterDetailMapperProvider{

        public String insert(CwInvoiceRegisterDetailPojo pojo){
            String sql = new SQL() {{
                INSERT_INTO("cw_invoice_register_detail");
                VALUES("id","#{id}");
                VALUES("cw_invoice_register_id","#{cwInvoiceRegisterId}");
                VALUES("native_bill_id","#{nativeBillId}");
                VALUES("invoice_code","#{invoiceCode}");
            }}.toString();
            return sql;
        }


        public String queryPojoById(String detailId){
            String sql= new SQL() {{
                SELECT("t.*");
                FROM("cw_invoice_register_detail t ");
                WHERE("1=1 and t.id = #{detailId}");
            }}.toString();
            return sql;
        }


        public String update(CwInvoiceRegisterDetailPojo pojo) {
            String sql= new SQL() {{
                UPDATE("cw_invoice_register_detail t");
                SET("t.cw_invoice_register_id = #{cwInvoiceRegisterId}");
                SET("t.native_bill_id = #{nativeBillId}");
                SET("t.invoice_code = #{invoiceCode}");
                WHERE("t.id=#{id}");
            }}.toString();
            return sql;
        }

    }


    /**
     * id
     * cw_invoice_register_id
     * native_bill_id
     * invoice_code
     * @param detailId
     * @return
     */

    @Results(id = "cwInvoiceRegisterDetailMapId",value = {
            @Result(column = "id", property = "id"),
            @Result(column = "cw_invoice_register_id", property = "cwInvoiceRegisterId"),
            @Result(column = "native_bill_id", property = "nativeBillId"),
            @Result(column = "invoice_code", property = "invoiceCode")
    })
    @SelectProvider(type = CwInvoiceRegisterDetailMapperProvider.class, method = "queryPojoById")
    CwInvoiceRegisterDetailPojo queryPojoById(String detailId);

    @InsertProvider(type = CwInvoiceRegisterDetailMapperProvider.class, method = "insert")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(CwInvoiceRegisterDetailPojo pojo);


    @UpdateProvider(type = CwInvoiceRegisterDetailMapperProvider.class, method = "update")
    int update(CwInvoiceRegisterDetailPojo obj);

}
